/*
* 多种方法实现数组去重功能
*/
class Removal {
  constructor(array) {
    this.array = array;
  }
  // 支持数组中的对象去重
  method_1 () {
    const temp = [];
    for (let i = 0; i < this.array.length; i++) {
      if (temp.indexOf(this.array[i]) == -1) {
        temp.push(this.array[i]);
      }
    }
    return temp;
  }
  method_2 () {
    let [temp, r, len, val, type] = [{}, [], this.array.length];
    for (let i = 0; i < len; i++) {
      val = this.array[i];
      type = typeof val;
      if (!temp[val]) {
        temp[val] = [type];
        r.push(val);
      } else if (temp[val].indexOf(type) < 0) {
        temp[val].push(type);
        r.push(val);
      }
    }
    return r;
  }
  method_3 () {
    const local_array = this.array.sort();
    const temp = [local_array[0]];
    for (let i = 1; i < local_array.length; i++) {
      if (local_array[i] !== temp[temp.length-1]) {
        temp.push(local_array[i]);
      }
    }
    return temp;
  }
  method_4 () {
    const temp = Array.from(new Set(this.array));
    return temp;
  }
  method_5 () {
    const temp = [];
    for (let i = 0; i < this.array.length; i++) {
      if (this.array.indexOf(this.array[i]) === i) {
        temp.push(this.array[i]);
      }
    }
    return temp;
  }
  method_6 () {
    const [temp, index, length] = [[], [], this.array.length];
    for (let i = 0; i < length; i++) {
      for (let j = i + 1; j < length; j++) {
        if (this.array[i] === this.array[j]) {
          i++;
          j = i;
        }
      }
      temp.push(this.array[i]);
      index.push(i);
    }
    return temp;
  }
}

const array = new Removal([1, 1, {name: 'dtx'}, 2, {name: 'dtx'}, 1, 22, 45, 2, '1', 'a', 'c', 'a', 22, true, false, false]);
console.log(array.method_2());